<template>
  <div class="h-full">
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :colon="false" :label-col="{ style: { width: '80px' } }">
        <a-form-item name="zjm" class="w-72">
          <a-input v-model:value="formState.zjm" placeholder="物品名称/物品编号/助记码" />
        </a-form-item>
        <a-form-item name="ckbh" label="仓库名称" class="w-64">
          <SelectWarehouse v-model:value="formState.ckbh" max-tag-count="responsive" :multiple="true" @change="onSelecthouse" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <a-space class="flex justify-end mb-2">
        <BaseExport type="物资" name="按批号查询" code="000166" :search-params="formState">导出</BaseExport>
      </a-space>
      <BaseTable :loading="loading" column-code="000166" :data-source="tableData" :pagination="pagination" :scroll="{ x: 1000 }" fill>
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'ypmc'">
            <MedicineInfo :value="{ mc: record.ypmc, gg: record.gg, cj: record.cj }" />
          </template>
          <template v-if="column.dataIndex === 'status'">
            <a-tag :color="record.status !== 0 ? 'red' : 'green'">{{ record.status !== 0 ? '停用' : '启用' }}</a-tag>
          </template>
          <template v-if="column.dataIndex === 'action'">
            <BaseButton type="link" size="small" @click="onClickEdit(record)">出入库明细</BaseButton>
          </template>
        </template>
      </BaseTable>
    </a-card>
    <Inventorydetails v-model:open="editOpen" :row-data="rowData" @success="onSuceess" />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { post } from '@/utils/request'
import BaseButton from '@/components/BaseButton'
import Inventorydetails from '../components/Inventorydetails'
// import { message } from 'ant-design-vue'
const options = ref([])

const formState = ref({ zjm: '' })
const editOpen = ref(false)
const rowData = ref(null)
const formRef = ref(null)
const { loading, tableData, pagination, getData } = useTable({
  url: '/oos/psiform/getStoreSummaryByDrugYxq',
  immediate: true,
  params: formState.value
})
const onSuceess = () => {
  getData()
}
const getProjectList = async () => {
  const { code, data } = await post('/oos/comprehenive/getProjectList')
  if (code !== 0) return
  options.value = data.map((item) => {
    return {
      label: item.mc,
      value: item.bh
    }
  })
}

const onClickEdit = (record = {}) => {
  editOpen.value = true
  rowData.value = record
}
onMounted(() => {
  getProjectList()
  getData()
})
</script>

<style lang="less" scoped></style>
